package com.frogs.ucenter.v1.service.impl;

import java.util.Arrays;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.ServiceOperationException;
//import com.frogs.ucenter.component.MailingHelper;
//import com.frogs.ucenter.util.mailing.RecordResultType;
import com.frogs.ucenter.v1.request.MailingMassSendRequest;
import com.frogs.ucenter.v1.request.MailingRecieverAddRequest;
import com.frogs.ucenter.v1.request.MailingSendRequest;
import com.frogs.ucenter.v1.response.AddResponse;
import com.frogs.ucenter.v1.response.DefaultResponse;
import com.frogs.ucenter.v1.service.MailingService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Service(ApiConstants.VERSION + "mailingService")
public class MailingServiceImpl implements MailingService {
	
	private Logger log = LoggerFactory.getLogger(MailingServiceImpl.class);
	
//	@Resource
//	private MailingHelper mailingHelper;

	/**
	 * 将收件人添加到邮件系统列表
	 */
	@Override
	public Response addReciever(Request request) throws Exception {
		try {
			MailingRecieverAddRequest addRequest = (MailingRecieverAddRequest)request;
//			AddResponse<RecordResultType> response = new AddResponse<RecordResultType>();
//			String email = addRequest.getEmail();
//			int compId = addRequest.getCompId();
//			int groupId = addRequest.getGroupId();
//			Map<String,Object> userParam = addRequest.getUserParam();
//			response.setInfo(mailingHelper.addReciever(email, groupId, compId, userParam));
//			response.setTip("添加收件人成功！");
			return null;
		} catch (Exception e) {
			log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	}

	@Override
	public Response sendMail(Request request) throws Exception{
		try {
//			MailingSendRequest sendRequest = (MailingSendRequest) request;
//			String reciever = sendRequest.getEmail();
//			Response sendResponse = new DefaultResponse();
//			int compId = sendRequest.getCompId();
//			int mailId = sendRequest.getMailId();
//			boolean result = mailingHelper.sendMail(reciever, mailId, compId);
//			if(result) {
//				sendResponse.setTip("发送成功");
//				return sendResponse;
//			} else {
//				throw new Exception("发送邮件失败");
//			}
			return null;
		} catch (Exception e) {
			log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	}

	/**
	 * 群发邮件
	 */
	@Override
	public Response sendMassMail(Request request) throws Exception {
		try {
			/*MailingMassSendRequest sendRequest = (MailingMassSendRequest)request;
			Response sendResponse = new DefaultResponse();
			int compId = sendRequest.getCompId();
			int mailId = sendRequest.getMailId();
			int groupId = sendRequest.getGroupId();
			
			boolean result = mailingHelper.sendMassMail(compId, mailId, groupId);
			
			if(result) {
				sendResponse.setTip("发送成功");
				return sendResponse;
			} else {
				throw new Exception("发送失败");
			}
			*/
			return null;
		} catch (Exception e) {
			log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	}

}
